
import java.util.Random;

public class Work {
    static Object locker = new Object();
    static int[] arr = new int[1000];
    static int sum1 = 0;
    static int sum2 = 0;
    public static void main(String[] args) throws InterruptedException {
        createArray();
        Thread t1 = new Thread(() -> {
            synchronized (locker) {
                for (int j = 0; j < arr.length; j +=2) {
                    if (j > arr.length-1) {
                        break;
                    }else {
                        sum1 += arr[j];
                    }
                }
            }
        });

        Thread t2 = new Thread(() -> {
           synchronized (locker) {
               for (int i = 1; i < arr.length; i+=2) {
                   if (i > arr.length -1) {
                       break;
                   }else {
                       sum2 += arr[i];
                   }
               }
           }
        });
        long l = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        int sum = sum1 + sum2;
        System.out.println(sum);
    }

    public static void createArray() {
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100);
        }
    }
}
